package com.qf.nio.selector;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

/**
 * @Description:
 * @Author: xbb
 * @Date:2020/4/20
 */
public class ClientDemo {
    public static void main(String[] args) throws Exception {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress(8080));
        System.out.println("客户端连接成功");
        while (true){
            Scanner scanner = new Scanner(System.in);
            String next = scanner.next();

            ByteBuffer byteBuffer = ByteBuffer.allocate(1024*10);
            byteBuffer.put(next.getBytes("utf-8"));
            byteBuffer.flip();
            socketChannel.write(byteBuffer);
        }

    }
}
